# -*- coding: utf-8 -*-

"""
Datetime: 2020/07/23
Author: Zhang Yafei
Description: 腾讯验证码识别
"""
from tencentcloud.common import credential
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.ocr.v20181119 import ocr_client, models


try:
    cred = credential.Credential("AKIDd2B38AQSjkVXIoa76oQmsnzznOaQiQcZ", "Aysra7Udtvkqj4C4mMyPzLFKONvDFAyA")
    httpProfile = HttpProfile()
    httpProfile.endpoint = "ocr.tencentcloudapi.com"

    clientProfile = ClientProfile()
    clientProfile.httpProfile = httpProfile
    client = ocr_client.OcrClient(cred, "ap-beijing", clientProfile)

    req = models.GeneralBasicOCRRequest()
    params = '{"ImageUrl": "http://www.dxy.cn/bbs/code.jpg?r=1595476991146"}'
    req.from_json_string(params)

    resp = client.GeneralBasicOCR(req)
    result = resp.TextDetections[0].DetectedText
    print(result)

except TencentCloudSDKException as err:
    print(err)
